package com.deere.scrap.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.deere.dao.GenericDao;
import com.deere.model.Scrap;
import com.deere.model.dto.ScrapDto;

@Service
public class ScrapService {
	
	@Autowired
	private GenericDao<Scrap> scrapDao;
	
	/**
	 * 根据条件查询报废零件
	 * @param scrapDto
	 * @return
	 */
	public List<Scrap> searchScrap(ScrapDto scrapDto){
		String queryString = "from Scrap where 1=1 ";
		String filter = "";
		if(null != scrapDto){
			if(null != scrapDto.getPartCode() && !"".equals(scrapDto.getPartCode())){
				filter = " and workOrder.partCode ='" +scrapDto.getPartCode()+"'";
			}
		}
		String sort = " order by modifiedDate asc";
		return scrapDao.query(queryString+filter+sort);
	}

}
